﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using OpenSISInstall;
using System.IO;
using OpenSIS.OpenSISWCFServiceReference;
using OSISDynamicTranslation;
using OpenSISStaffDropDownList;

namespace OpenSIS.Staff
{
    public partial class AddStaff : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SISInstall SISInstall = new SISInstall();
            //SchoolBL schoolAdd = new SchoolBL();

            OpenSISWCFServiceInstallationClient OSISinstallClient = new OpenSISWCFServiceInstallationClient();

            DataTable dtDateFormat = OSISinstallClient.getdateformat();
            OSISinstallClient.Close();

            if (dtDateFormat.Rows.Count > 0)
            {
                SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
            }

            CalDobDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalJoinDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            calExtCertDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtCertExpDt.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtLeftDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();

            if (Session["StaffImage"] != null)
            {
                divPhotoUpload.Style.Add("background-image", "url(" + Session["StaffImage"].ToString().Replace("~", "..") + ")");
            }

            if (txtStaPass.Text != "")
            {
                hdnPasswrd.Value = txtStaPass.Text.ToString();
            }

            if (!Page.IsPostBack)
            {
                PopulateCategoryTree();
                tvCategories.Nodes[0].Select();
                PopulateAllControls();

                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            }
            chkSame.Attributes.Add("onclick", "CheckSameAddress()");
        }

        public void PopulateCategoryTree()
        {
            DynamicTranslation DTL = new DynamicTranslation();
            string langto = Session["MLUICulture"].ToString();
            try
            {
                tvCategories.Nodes.Clear();


                TreeNode TreeNodeDemoInfo = new TreeNode();

                string s = "Demographic Information";
                string t = DTL.Translate(s, "en", langto);
                TreeNodeDemoInfo.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeDemoInfo.Value = Convert.ToString("0");
                tvCategories.Nodes.Add(TreeNodeDemoInfo);

                s = "Address and Contact";
                t = DTL.Translate(s, "en", langto);
                TreeNode TreeNodeAddCont = new TreeNode();
                TreeNodeAddCont.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeAddCont.Value = Convert.ToString("1");
                tvCategories.Nodes.Add(TreeNodeAddCont);

                s = "School Information";
                t = DTL.Translate(s, "en", langto);
                TreeNode TreeNodeSchoolInfo = new TreeNode();
                TreeNodeSchoolInfo.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeSchoolInfo.Value = Convert.ToString("2");
                tvCategories.Nodes.Add(TreeNodeSchoolInfo);

                s = "Certification Information";
                t = DTL.Translate(s, "en", langto);
                TreeNode TreeNodeCertificate = new TreeNode();
                TreeNodeCertificate.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeCertificate.Value = Convert.ToString("3");
                tvCategories.Nodes.Add(TreeNodeCertificate);


                tvCategories.ExpandAll();
            }
            catch
            { }

        }

        protected void tvCategories_SelectedNodeChanged(object sender, EventArgs e)
        {
            // StaffBL STABL = new StaffBL();
            try
            {
                if (txtStaPass.Text != "")
                {
                    hdnPasswrd.Value = txtStaPass.Text.ToString();
                }
                string CatValue = tvCategories.SelectedNode.Value;
                mvCategories.ActiveViewIndex = Convert.ToInt32(CatValue);
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
                hdnCatId.Value = Convert.ToString(category);
                if (category > 0)
                {
                    btnPrev.Visible = true;
                }
                if (category + 1 == tvCategories.Nodes.Count)
                {
                    btnNext.Visible = false;
                    btnSave.Visible = true;
                }
                if (category + 1 < tvCategories.Nodes.Count)
                {
                    btnNext.Visible = true;
                    btnSave.Visible = false;
                }
                if (category == 0)
                {
                    btnPrev.Visible = false;
                }
                if (mvCategories.ActiveViewIndex == 0)
                {
                    btnNext.ValidationGroup = "vgDemoInfo";
                    if (rbtnDisability.SelectedItem.Value == "Y")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='block'", true);
                    }
                }
                if (mvCategories.ActiveViewIndex == 1)
                {
                    btnNext.ValidationGroup = "vgAddrInfo";
                }
                if (mvCategories.ActiveViewIndex == 2)
                {
                    btnNext.ValidationGroup = "vgSchlInfo";
                    txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                    if (rbtnOpenAccess.SelectedIndex != -1)
                    {
                        if (rbtnOpenAccess.SelectedItem.Value == "N")
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                        }
                    }
                    if (rbtnLibAcc.SelectedIndex != -1)
                    {
                        if (rbtnLibAcc.SelectedItem.Value == "N")
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                        }
                    }
                    if (rbtnOpenAccess.SelectedIndex == -1)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                    }
                    if (rbtnLibAcc.SelectedIndex == -1)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                    }
                }
                if (mvCategories.ActiveViewIndex == 3)
                {
                    if (hdnBlankgrid.Value != "Filled")
                    {
                        hdnBlankgrid.Value = "Blank";
                        DataTable dtcertblnk = new DataTable();
                        dtcertblnk.Columns.Add("stf_cert_dt");
                        dtcertblnk.Columns.Add("stf_cert_exp_dt");
                        dtcertblnk.Columns.Add("stf_cert_cd");
                        dtcertblnk.Columns.Add("stf_cert_short_nm");
                        dtcertblnk.Columns.Add("stf_cert_nm");
                        dtcertblnk.Columns.Add("stf_pri_cert_ind");
                        dtcertblnk.Columns.Add("stf_cert_desc");
                        DataRow dr = dtcertblnk.NewRow();
                        dr["stf_cert_dt"] = "";
                        dr["stf_cert_exp_dt"] = "";
                        dr["stf_cert_cd"] = "";
                        dr["stf_cert_short_nm"] = "";
                        dr["stf_cert_nm"] = "";
                        dr["stf_pri_cert_ind"] = "";
                        dr["stf_cert_desc"] = "";
                        dtcertblnk.Rows.Add(dr);
                        gvCertficates.DataSource = dtcertblnk;
                        gvCertficates.DataBind();
                    }
                }
            }
            catch
            {
            }
        }

        public void PopulateAllControls()
        {
            StaffDropDown STABL = new StaffDropDown();
            try
            {
                STABL.PopulateEthnicity(ref ddlEthnicity, Convert.ToInt32(Session["SchoolID"]));
                STABL.PopulateLanguage(ref ddlLang);
                STABL.PopulateLanguage(ref ddlSecnLang);
                STABL.PopulateLanguage(ref ddlThrdLang);
                //STABL.PopulateState(ref ddlStaffState);
                STABL.PopulateState(ref ddlSecnState);
                STABL.PopulateState(ref ddlState);
                STABL.PopulateStaffType(ref ddlStaffTyp);
                STABL.PopulateSchools(ref ddlSchools);
                STABL.PopulateSchoolsCheckbox(ref chkschools);
                STABL.PopulateGender(ref ddlGender);
                STABL.PopulateSalutation(ref ddlSalutation);
                STABL.PopulateSuffix(ref ddlSuffix);
                STABL.PopulateRelationShip(ref ddlRelation);
                STABL.PopulateStatus(ref ddlStatus);
                STABL.PopulateLibraryClass(ref ddlLibCLass);
                STABL.PopulateSecretquestion(ref ddlsecrQues);
            }
            catch
            {

            }
            finally
            {
                STABL = null;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Function Func = new Function();
            //StaffBL STABL = new StaffBL();
            try
            {
                string FirstName = txtStaFrstNam.Text;
                string MiddleName = txtStaMidlNam.Text;
                string LastName = txtStalstNam.Text;
                string Gender = ddlGender.SelectedItem.Value;
                string DOB = txtDOB.Text;
                string Language = ddlLang.SelectedItem.Value;
                string Secondlang = ddlSecnLang.SelectedItem.Value;
                string Thirdlang = ddlThrdLang.SelectedItem.Value;
                string Ethnicity = ddlEthnicity.SelectedItem.Value;
                string Salutation = ddlSalutation.SelectedItem.Value;
                string Suffix = ddlSuffix.SelectedItem.Value;
                string Disability = rbtnDisability.SelectedItem.Value.Trim();
                string Disabilitydesc = txtDisDesc.Text;
                string StaffIdNumber = txtStaffId.Text;
                string Alternateid = txtAltrntId.Text;
                string PrimaryAddress1 = txtAdd1.Text;
                string PrimaryAddress2 = txtAdd2.Text;
                string PrimaryCity = txtCity.Text;
                string PrimaryState = ddlState.SelectedItem.Value;
                string PrimaryZip = txtZip.Text;
                string SecondaryAddress1 = txtSecnAdd1.Text;
                string SecondaryAddress2 = txtSecnAdd2.Text;
                string SecondaryCity = txtSecnCity.Text;
                string SecondaryState = ddlSecnState.SelectedItem.Value;
                string SecondaryZip = txtSecnZip.Text;
                string PoBox = txtPObox.Text;
                string HomePhone = txtHomePhn.Text;
                string MobilPhon = txtMobPhn.Text;
                string Officphon = txtOffcPhn.Text;
                string WorkEmail = txtWrkEmail.Text;
                string Personalemail = txtPersEmail.Text;
                string Emrgnemail = txtEmrgnEmail.Text;
                string Emrgnfirstnam = txtEmrgnFrstNam.Text;
                string EmrgnHomePhon = txtEmrgnHomPhn.Text;
                string Emrgnlastnam = txtEmrgnLastNam.Text;
                string Emrgnrelationship = ddlRelation.SelectedItem.Value;
                string EmrgnWorkPhon = txtEmrgnWrkPhn.Text;
                string EmrgnMobilePhon = txtEmrgnMobPhn.Text;
                int HomeSchoolId = Convert.ToInt32(ddlSchools.SelectedItem.Value);
                string JoiningDate = txtDateJoin.Text;
                string LeftDate = txtleftdate.Text;
                string Jobtitle = txtJobTitle.Text;
                string StaffType = ddlStaffTyp.SelectedItem.Value;
                string OpensisAcces = rbtnOpenAccess.SelectedItem.Value.Trim();
                //string Role = ddlOpenProf.SelectedItem.Value;
                string Username = txtStaUsrnam.Text;
                string Password = hdnPasswrd.Value;
                // string SecretQuestn = txtSecQues.Text;
                string SecretQuestn = ddlsecrQues.SelectedItem.Value;
                string SecretAnswr = txtSecrAnsr.Text;
                string Status = ddlStatus.SelectedItem.Value;
                string LibraryAccess = "";
                if (rbtnLibAcc.SelectedIndex != -1)
                {
                    LibraryAccess = rbtnLibAcc.SelectedItem.Value.Trim();
                }
                string LibraryCard = txtLibCrdNo.Text;
                string LibraryClass = ddlLibCLass.SelectedItem.Value;
                //Staff Details 

                OpenSISWCFServiceStaffClient OSClient111 = new OpenSISWCFServiceStaffClient();

                int StaffId = OSClient111.InsertStaffDetails(Language, Gender, Ethnicity, FirstName, MiddleName, LastName, DOB, "", StaffIdNumber, Alternateid, Salutation, Suffix, Secondlang, Thirdlang, Disability, Disabilitydesc);
                OSClient111.Close();



                OpenSISWCFServiceStaffClient OSClient2 = new OpenSISWCFServiceStaffClient();

                OSClient2.InsertStaffAddressDetails(StaffId, PrimaryAddress1, PrimaryAddress2, PrimaryCity, PrimaryState, PrimaryZip, SecondaryAddress1, SecondaryAddress2, SecondaryCity, SecondaryState, SecondaryZip, "", PoBox);
                OSClient2.Close();

                OpenSISWCFServiceStaffClient OSClient3 = new OpenSISWCFServiceStaffClient();
                OSClient3.InsertStaffPhoneDetails(StaffId, "", HomePhone, MobilPhon, Officphon, WorkEmail, Personalemail);
                OSClient3.Close();

                //Staff Access Details insert Commented for table related confusion
                OpenSISWCFServiceStaffClient OSClient4 = new OpenSISWCFServiceStaffClient();
                OSClient4.InsertStaffSchoolJoinDetails(HomeSchoolId, StaffId, JoiningDate, LeftDate, "", Jobtitle, StaffType);
                OSClient4.Close();

                string schoolname = "";
                foreach (ListItem cBox in chkschools.Items)
                {
                    if (cBox.Selected)
                    {
                        schoolname += cBox.Value + " , ";
                    }
                }
                string SchoolAccess = schoolname;

                OpenSISWCFServiceStaffClient OSClient5 = new OpenSISWCFServiceStaffClient();
                OSClient5.InsertStaffAccessDetails(StaffId, Username, Password, "", SecretQuestn, SecretAnswr, OpensisAcces, SchoolAccess);
                OSClient5.Close();

                //STABL.SchoolName = schoolname;
                if (rbtnLibAcc.SelectedIndex != -1)
                {
                    OpenSISWCFServiceStaffClient OSClient6 = new OpenSISWCFServiceStaffClient();
                    OSClient6.InsertStaffLibraryDetails(StaffId, LibraryCard, LibraryClass, Status, LibraryAccess);
                    OSClient6.Close();
                }

                OpenSISWCFServiceStaffClient OSClient7 = new OpenSISWCFServiceStaffClient();
                OSClient7.InsertStaffEmergncyContact(StaffId, Emrgnfirstnam, Emrgnlastnam, Emrgnrelationship, EmrgnHomePhon, EmrgnMobilePhon, EmrgnWorkPhon, Emrgnemail);
                OSClient7.Close();

                DataTable dtcertificates = (DataTable)Session["CertTable"];
                if (dtcertificates != null)
                {
                    for (int i = 0; i < dtcertificates.Rows.Count; i++)
                    {
                        string CertDate = dtcertificates.Rows[i]["stf_cert_dt"].ToString();
                        string CertCode = dtcertificates.Rows[i]["stf_cert_cd"].ToString();
                        string CertShortName = dtcertificates.Rows[i]["stf_cert_short_nm"].ToString();
                        string CertName = dtcertificates.Rows[i]["stf_cert_nm"].ToString();
                        string Primarycert = dtcertificates.Rows[i]["stf_pri_cert_ind"].ToString();
                        string CertExpirDate = dtcertificates.Rows[i]["stf_cert_exp_dt"].ToString();
                        string CertDescription = dtcertificates.Rows[i]["stf_cert_desc"].ToString();

                        OpenSISWCFServiceStaffClient OSClient8 = new OpenSISWCFServiceStaffClient();
                        OSClient8.InsertStaffCertificateDetails(StaffId, CertDate, CertExpirDate, CertCode, CertShortName, CertName, Primarycert, "", CertDescription);
                        OSClient8.Close();
                    }
                }

                string PhotoUrl = "";

                if (Session["StaffImage"] != null)
                {
                    PhotoUrl = Session["StaffImage"].ToString().Replace("~", "..");
                }
                else
                {
                    PhotoUrl = "../App_Themes/main/images/no_pic.png";
                }

                OpenSISWCFServiceStaffClient OSClient9 = new OpenSISWCFServiceStaffClient();
                OSClient9.savestaffphoto(StaffId, HomeSchoolId, PhotoUrl);
                OSClient9.Close();

                if (Session["WorkingImage"] != null)
                {
                    string uploadedimage = "~/Garbage Image/" + Session["WorkingImage"].ToString();
                    File.Delete(Server.MapPath(uploadedimage));
                    Session["WorkingImage"] = null;
                }
                if (Session["StaffImage"] != null)
                {
                    Session["StaffImage"] = null;
                }
                Session["CertTable"] = null;
                //Func.ResetFormControlValues(this.Page);
                //gvCertficates.Columns.Clear();
                Session["StaffId"] = StaffId;
                Session["SchoolID"] = HomeSchoolId;
                Session["DirectView"] = "DV";
                Response.Redirect("StaffInfo.aspx");
            }
            catch
            {
            }
            finally
            {

            }
        }

        protected void btnNext_Click(object sender, ImageClickEventArgs e)
        {
            //StaffBL STABL = new StaffBL();
            try
            {
                if (txtStaPass.Text != "")
                {
                    hdnPasswrd.Value = txtStaPass.Text.ToString();
                }
                int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
                tvCategories.Nodes[category + 1].Select();
                mvCategories.ActiveViewIndex = category + 1;
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                hdnCatId.Value = Convert.ToString(category);
                if (category + 1 > 0)
                {
                    btnPrev.Visible = true;
                }
                if (category + 2 == tvCategories.Nodes.Count)
                {
                    btnNext.Visible = false;
                    btnSave.Visible = true;
                }
                if (mvCategories.ActiveViewIndex == 0)
                {
                    btnNext.ValidationGroup = "vgDemoInfo";
                    if (rbtnDisability.SelectedItem.Value == "Y")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='block'", true);
                    }
                }
                if (mvCategories.ActiveViewIndex == 1)
                {
                    btnNext.ValidationGroup = "vgAddrInfo";
                }
                if (mvCategories.ActiveViewIndex == 2)
                {
                    btnNext.ValidationGroup = "vgSchlInfo";
                    txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                    //changed
                    if (rbtnOpenAccess.SelectedIndex != -1)
                    {
                        if (rbtnOpenAccess.SelectedItem.Value == "N")
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                        }
                    }
                    if (rbtnLibAcc.SelectedIndex != -1)
                    {
                        if (rbtnLibAcc.SelectedItem.Value == "N")
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                        }
                    }
                    if (rbtnOpenAccess.SelectedIndex == -1)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                    }
                    if (rbtnLibAcc.SelectedIndex == -1)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                    }
                }
                if (mvCategories.ActiveViewIndex == 3)
                {
                    if (hdnBlankgrid.Value != "Filled")
                    {
                        hdnBlankgrid.Value = "Blank";
                        DataTable dtcertblnk = new DataTable();
                        dtcertblnk.Columns.Add("stf_cert_dt");
                        dtcertblnk.Columns.Add("stf_cert_exp_dt");
                        dtcertblnk.Columns.Add("stf_cert_cd");
                        dtcertblnk.Columns.Add("stf_cert_short_nm");
                        dtcertblnk.Columns.Add("stf_cert_nm");
                        dtcertblnk.Columns.Add("stf_pri_cert_ind");
                        dtcertblnk.Columns.Add("stf_cert_desc");
                        DataRow dr = dtcertblnk.NewRow();
                        dr["stf_cert_dt"] = "";
                        dr["stf_cert_exp_dt"] = "";
                        dr["stf_cert_cd"] = "";
                        dr["stf_cert_short_nm"] = "";
                        dr["stf_cert_nm"] = "";
                        dr["stf_pri_cert_ind"] = "";
                        dr["stf_cert_desc"] = "";
                        dtcertblnk.Rows.Add(dr);
                        gvCertficates.DataSource = dtcertblnk;
                        gvCertficates.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
        }

        protected void btnPrev_Click(object sender, ImageClickEventArgs e)
        {
            //StaffBL STABL = new StaffBL();
            try
            {
                if (txtStaPass.Text != "")
                {
                    hdnPasswrd.Value = txtStaPass.Text.ToString();
                }
                int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
                tvCategories.Nodes[category - 1].Select();
                mvCategories.ActiveViewIndex = category - 1;
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                if (category - 1 == 0)
                {
                    btnPrev.Visible = false;
                }
                if (category < tvCategories.Nodes.Count)
                {
                    btnNext.Visible = true;
                    btnSave.Visible = false;
                }
                if (mvCategories.ActiveViewIndex == 0)
                {
                    btnNext.ValidationGroup = "vgDemoInfo";
                    if (rbtnDisability.SelectedItem.Value == "Y")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='block'", true);
                    }
                }
                if (mvCategories.ActiveViewIndex == 1)
                {
                    btnNext.ValidationGroup = "vgAddrInfo";
                }
                if (mvCategories.ActiveViewIndex == 2)
                {
                    btnNext.ValidationGroup = "vgSchlInfo";
                    txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                    if (rbtnOpenAccess.SelectedIndex != -1)
                    {
                        if (rbtnOpenAccess.SelectedItem.Value == "N")
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                        }
                    }
                    if (rbtnLibAcc.SelectedIndex != -1)
                    {
                        if (rbtnLibAcc.SelectedItem.Value == "N")
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                        }
                    }
                    if (rbtnOpenAccess.SelectedIndex == -1)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                    }
                    if (rbtnLibAcc.SelectedIndex == -1)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
        }

        protected void btnSaveCert_Click(object sender, EventArgs e)
        {
            try
            {
                if (hdnBlankgrid.Value == "Blank")
                {
                    hdnBlankgrid.Value = "Filled";
                    DataTable dtcert = new DataTable();
                    dtcert.Columns.Add("stf_cert_dt");
                    dtcert.Columns.Add("stf_cert_exp_dt");
                    dtcert.Columns.Add("stf_cert_cd");
                    dtcert.Columns.Add("stf_cert_short_nm");
                    dtcert.Columns.Add("stf_cert_nm");
                    dtcert.Columns.Add("stf_pri_cert_ind");
                    dtcert.Columns.Add("stf_cert_desc");
                    DataRow dr = dtcert.NewRow();
                    dr["stf_cert_dt"] = txtCertDate.Text;
                    dr["stf_cert_exp_dt"] = txtCertExpDat.Text;
                    dr["stf_cert_cd"] = txtCertCode.Text;
                    dr["stf_cert_short_nm"] = txtCertShrtName.Text;
                    dr["stf_cert_nm"] = txtCertName.Text;
                    if (rbtnPrimrCert.SelectedIndex != -1)
                    {
                        dr["stf_pri_cert_ind"] = rbtnPrimrCert.SelectedItem.Value;
                    }
                    dr["stf_cert_desc"] = txtCertDesc.Text;
                    dtcert.Rows.Add(dr);
                    gvCertficates.DataSource = dtcert;
                    gvCertficates.DataBind();
                    Session.Add("CertTable", dtcert);
                }
                else
                {
                    DataTable dt = (DataTable)Session["CertTable"];
                    DataRow dr = dt.NewRow();
                    dr["stf_cert_dt"] = txtCertDate.Text;
                    dr["stf_cert_exp_dt"] = txtCertExpDat.Text;
                    dr["stf_cert_cd"] = txtCertCode.Text;
                    dr["stf_cert_short_nm"] = txtCertShrtName.Text;
                    dr["stf_cert_nm"] = txtCertName.Text;
                    if (rbtnPrimrCert.SelectedIndex != -1)
                    {
                        dr["stf_pri_cert_ind"] = rbtnPrimrCert.SelectedItem.Value;
                    }
                    dr["stf_cert_desc"] = txtCertDesc.Text;
                    dt.Rows.Add(dr);
                    gvCertficates.DataSource = dt;
                    gvCertficates.DataBind();
                    Session.Add("CertTable", dt);
                }
                txtCertDate.Text = "";
                txtCertExpDat.Text = "";
                txtCertCode.Text = "";
                txtCertShrtName.Text = "";
                txtCertName.Text = "";
                rbtnPrimrCert.SelectedIndex = -1;
                txtCertDesc.Text = "";
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
        }

        protected void gvCertficates_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblPrimryCert = (Label)e.Row.FindControl("lblPrimryCert");

                if (lblPrimryCert.Text == "Y")
                {
                    lblPrimryCert.Text = "Yes";
                }
                else if (lblPrimryCert.Text == "")
                {
                    lblPrimryCert.Text = "";
                }
                else
                {
                    lblPrimryCert.Text = "No";
                }
            }
        }

        protected void rbtnOpenAccess_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rbtnOpenAccess.SelectedValue == "Y")
            {
                rfvPass.Enabled = true;
                rfvSecretQues.Enabled = true;
                cvlChkSchl.Enabled = true;
                rfvSecrAnsr.Enabled = true;
                rfvLibAcces.Enabled = true;
                rfvUsernam.Enabled = true;
                rfvLibAcces.Enabled = true;
                //pnlOpenAcces.Visible = true;
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='block'", true);
                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='block'", true);
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
            }
            else
            {
                rbtnLibAcc.SelectedIndex = -1;
                rfvLibAcces.Enabled = false;
                rfvPass.Enabled = false;
                rfvSecretQues.Enabled = false;
                rfvSecrAnsr.Enabled = false;
                cvlChkSchl.Enabled = false;
                rfvUsernam.Enabled = false;
                rfvLibAcces.Enabled = false;
                //pnlOpenAcces.Visible = false;
                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
            }
        }

        protected void rbtnLibAcc_SelectedIndexChanged(object sender, EventArgs e)
        {
            OpenSISWCFServiceStaffClient OSClient = new OpenSISWCFServiceStaffClient();

            if (rbtnLibAcc.SelectedValue == "Y")
            {
                rfvStatus.Enabled = true;
                rfvCardNo.Enabled = true;
                rfvLibCLas.Enabled = true;
                //pnlLib.Visible = true;

                txtLibCrdNo.Text = OSClient.GenerateRandomNumber();

                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='block';document.getElementById('divlib').style.display='block'", true);
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='block'", true);
            }
            else
            {
                rfvStatus.Enabled = false;
                rfvCardNo.Enabled = false;
                rfvLibCLas.Enabled = false;
                txtLibCrdNo.Text = "";
                ddlLibCLass.ClearSelection();
                ddlStatus.ClearSelection();
                ddlLibCLass.Items.FindByValue("0").Selected = true;
                ddlStatus.Items.FindByValue("0").Selected = true;
                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
            }
        }

        protected void rbtnDisability_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rbtnDisability.SelectedItem.Value == "N")
            {
                hdndisdesc.Value = txtDisDesc.Text;
                txtDisDesc.Text = "";
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='block'", true);
                txtDisDesc.Text = hdndisdesc.Value;
            }
        }

        private void ml_InitCulture()
        {
            if (Session["MLCulture"] != null && Session["MLUICulture"] != null)
            {
                String MLCultureName = (String)Session["MLCulture"];
                //sCulture = Session["MLCulture"].ToString();
                String MLUICultureName = (String)Session["MLUICulture"];

                if ((MLCultureName != null) && (MLCultureName.Length > 0))
                {
                    Page.Culture = MLCultureName;
                }

                if ((MLUICultureName != null) && (MLUICultureName.Length > 0))
                {
                    Page.UICulture = MLUICultureName;
                }
            }
        }

        protected override void InitializeCulture()
        {
            ml_InitCulture();
        }
    }
}